"""
@name : 7.13作业
@author : Zhao Junjie
@projectname: pythonProject1
"""

# 练习一：
list1 = [7, -8, 5, 4, 0, -2, -5]
list2 = sorted(list1, key=lambda x:(x<0, abs(x)))
print(list2)


# 练习二：
s = "asdf234GDdsf23"
result = sorted(s,key=lambda x:(x.isupper() or x.isdigit(), \
        x.isdigit(), x.isdigit() and int(x)%2==0))
print(result)



# 练习三：
from functools import reduce
def f(x,y):
    if x.isdigit() and y.isdigit():
        return x + y
    elif x.isdigit():
        return x
    elif y.isdigit():
        return y

lst = ['a', '1', '2bb', '234', '', '9']
result = reduce(f,lst)
print(result)